package com.mp.approvalreq.entity;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.mp.user.entity.User;

import java.util.Objects;

public class Flow {

    // 未排到
    public static final int NOT_YET = -2;
    // 跳过（或签）
    public static final int SKIP = -1;

    public static final int APPROVING = 0;

    public static final int CONFIRM = 1;

    public static final int REFUSED = 2;

    public static final int MODE_DEFAULT = 0;

    public static final int MODE_AND = 1;

    public static final int MODE_OR = 2;

    public static final int FLOW_TYPE_DEFAULT = 0;

    public static final int FLOW_TYPE_FINANCIAL = 1;

    @JSONField(serialize = false)
    private int id;

    @JSONField(serialize = false)
    private int requestId;

    @JSONField(serialize = false)
    private int companyId;

    private int companyInfoId;

    private int contactId;
    /**
     * 审批层级  1、2……
     */
    private int ordering;
    /**
     * 审批模式 0.逐层; 1.会签; 2.或签
     */
    private int type;
    /**
     * 是否批准  -1.无须处理 0.待处理 1.批准 2.驳回
     */
    private int isApproved;
    /**
     * 批准/驳回时间
     */
    private String isApprovedAt;
    /**
     * 审批流类型  0.普通审批流; 1.财务审批流
     */
    private int flowType;
    /**
     * 状态 1.有效 2.无效 （审批作废时需要同步更新）
     */
    @JSONField(serialize = false)
    private int state;

    public Flow() {
    }

    public Flow(User user) {
        this.companyId = user.getCompanyId();
        this.companyInfoId = user.getCompanyInfoId();
        this.contactId = user.getContactId();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getRequestId() {
        return requestId;
    }

    public void setRequestId(int requestId) {
        this.requestId = requestId;
    }

    public int getCompanyId() {
        return companyId;
    }

    public void setCompanyId(int companyId) {
        this.companyId = companyId;
    }

    public int getCompanyInfoId() {
        return companyInfoId;
    }

    public void setCompanyInfoId(int companyInfoId) {
        this.companyInfoId = companyInfoId;
    }

    public int getContactId() {
        return contactId;
    }

    public void setContactId(int contactId) {
        this.contactId = contactId;
    }

    public int getOrdering() {
        return ordering;
    }

    public void setOrdering(int ordering) {
        this.ordering = ordering;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getIsApproved() {
        return isApproved;
    }

    public void setIsApproved(int isApproved) {
        this.isApproved = isApproved;
    }

    public String getIsApprovedAt() {
        return isApprovedAt;
    }

    public void setIsApprovedAt(String isApprovedAt) {
        this.isApprovedAt = isApprovedAt;
    }

    public int getFlowType() {
        return flowType;
    }

    public void setFlowType(int flowType) {
        this.flowType = flowType;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public boolean hasConfirmed() {
        return Objects.equals(CONFIRM, isApproved);
    }

    public boolean hasRefuse() {
        return Objects.equals(REFUSED, isApproved);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Flow flow = (Flow) o;
        return companyInfoId == flow.companyInfoId &&
                ordering == flow.ordering &&
                type == flow.type;
    }

    @Override
    public int hashCode() {
        return Objects.hash(companyInfoId, ordering, type);
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
}

